 import { useState, useEffect } from "react"

function Header() {
  useEffect(() => {
    let timerId = setInterval(() => {
      console.log('定时器每隔1s执行一次', Date.now());
    }, 1000);
    // 添加一个返回的回调函数，模拟 类组件卸载的钩子函数 componentWillUnmount
    return () => {
      clearInterval(timerId)
    }
  }, [])

  return (
    <div>子组件</div>
  )
}

function App() {
  const [count, setCount] = useState(3)
  return (
    <>
      { count > 2 && <Header />}
      <button onClick={() => setCount(count - 1)}>测试count的值---{count}</button>
    </>
  )
}

export default App